Prevent dragging groups into groups. Fixes #8706
[adiumx.git] / Plugins / General Preferences / ESGeneralPreferences.m
blob7afce0b6db5507e8f220bd7f4d1563aae4f16b5f
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6  * General Public License as published by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11  * Public License for more details.
12  * 
13  * You should have received a copy of the GNU General Public License along with this program; if not,
14  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15  */
17 #import <Adium/AIContentControllerProtocol.h>
18 #import <Adium/AIInterfaceControllerProtocol.h>
19 #import "AISoundController.h"
20 #import "ESGeneralPreferences.h"
21 #import "ESGeneralPreferencesPlugin.h"
22 #import "PTHotKeyCenter.h"
23 #import "PTHotKey.h"
24 #import "SRRecorderControl.h"
25 #import "PTHotKey.h"
26 #import "AIMessageHistoryPreferencesWindowController.h"
27 #import "AIMessageWindowController.h"
28 #import <Adium/AIServiceIcons.h>
29 #import <Adium/AIStatusIcons.h>
30 #import <AIUtilities/AIColorAdditions.h>
31 #import <AIUtilities/AIFontAdditions.h>
32 #import <AIUtilities/AIImageAdditions.h>
33 #import <AIUtilities/AIMenuAdditions.h>
34 #import <AIUtilities/AIPopUpButtonAdditions.h>
36 #define PREF_GROUP_DUAL_WINDOW_INTERFACE        @"Dual Window Interface"
37 #define KEY_TABBAR_POSITION                                     @"Tab Bar Position"
39 @interface ESGeneralPreferences (PRIVATE)
40 - (NSMenu *)tabChangeKeysMenu;
41 - (NSMenu *)sendKeysMenu;
42 - (NSMenu *)tabPositionMenu;
44 - (NSMenu *)statusIconsMenu;
45 - (NSMenu *)serviceIconsMenu;
46 - (NSArray *)_allPacksWithExtension:(NSString *)extension inFolder:(NSString *)inFolder;
47 @end
49 @implementation ESGeneralPreferences
51 // XXX in order to edit the nib, you need the ShortcutReporter palette
52 // You can download it at http://evands.penguinmilitia.net/ShortcutRecorder.palette.zip
53 // This comes from http://wafflesoftware.net/shortcut/
55 //Preference pane properties
56 - (NSString *)paneIdentifier
58         return @"General";
60 - (NSString *)paneName{ 
61     return AILocalizedString(@"General","General preferences label");
63 - (NSString *)nibName{
64     return @"GeneralPreferences";
66 - (NSImage *)paneIcon
68         return [NSImage imageNamed:@"pref-general" forClass:[self class]];
71 //Configure the preference view
72 - (void)viewDidLoad
74         BOOL                    sendOnEnter, sendOnReturn;
75         
76         //Interface
77     [checkBox_messagesInTabs setState:[[[adium preferenceController] preferenceForKey:KEY_TABBED_CHATTING
78                                                                                                                                                                 group:PREF_GROUP_INTERFACE] boolValue]];
79         [checkBox_arrangeByGroup setState:[[[adium preferenceController] preferenceForKey:KEY_GROUP_CHATS_BY_GROUP
80                                                                                                                                                                 group:PREF_GROUP_INTERFACE] boolValue]];
81         
82         // Update Checking
83         [checkBox_updatesAutomatic setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"SUCheckAtStartup"]];
84         [checkBox_updatesProfileInfo setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"SUIncludeProfile"]];
85         [checkBox_updatesIncludeBetas setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"AIAlwaysUpdateToBetas"]];
87         //Chat Cycling
88         [popUp_tabKeys setMenu:[self tabChangeKeysMenu]];
89         [popUp_tabKeys compatibleSelectItemWithTag:[[[adium preferenceController] preferenceForKey:KEY_TAB_SWITCH_KEYS
90                                                                                                                                                                                  group:PREF_GROUP_CHAT_CYCLING] intValue]];
92         //General
93         sendOnEnter = [[[adium preferenceController] preferenceForKey:SEND_ON_ENTER
94                                                                                                                         group:PREF_GROUP_GENERAL] boolValue];
95         sendOnReturn = [[[adium preferenceController] preferenceForKey:SEND_ON_RETURN
96                                                                                                                         group:PREF_GROUP_GENERAL] boolValue];
97         [popUp_sendKeys setMenu:[self sendKeysMenu]];
98         
99         if (sendOnEnter && sendOnReturn) {
100                 [popUp_sendKeys compatibleSelectItemWithTag:AISendOnBoth];
101         } else if (sendOnEnter) {
102                 [popUp_sendKeys compatibleSelectItemWithTag:AISendOnEnter];                     
103         } else if (sendOnReturn) {
104                 [popUp_sendKeys compatibleSelectItemWithTag:AISendOnReturn];
105         }
107         [popUp_tabPositionMenu setMenu:[self tabPositionMenu]];
108         [popUp_tabPositionMenu compatibleSelectItemWithTag:[[[adium preferenceController] preferenceForKey:KEY_TABBAR_POSITION
109                                                                                                                                                                                                  group:PREF_GROUP_DUAL_WINDOW_INTERFACE] intValue]];
110         
111         //Quit
112         //[checkBox_confirmOnQuit setState:[[[adium preferenceController] preferenceForKey:KEY_CONFIRM_QUIT
113         //                                                                                                                                                      group:PREF_GROUP_CONFIRMATIONS] boolValue]];
114         
115         //Global hotkey
116         PTKeyCombo *keyCombo = [[[PTKeyCombo alloc] initWithPlistRepresentation:[[adium preferenceController] preferenceForKey:KEY_GENERAL_HOTKEY
117                                                                                                                                                                                                                                          group:PREF_GROUP_GENERAL]] autorelease];
118         [shortcutRecorder setKeyCombo:SRMakeKeyCombo([keyCombo keyCode], [shortcutRecorder carbonToCocoaFlags:[keyCombo modifiers]])];
119         [shortcutRecorder setAnimates:YES];
120         [shortcutRecorder setStyle:SRGreyStyle];
122     [self configureControlDimming];
125 //Called in response to all preference controls, applies new settings
126 - (IBAction)changePreference:(id)sender
128     if (sender == popUp_tabKeys) {
129                 AITabKeys keySelection = [[sender selectedItem] tag];
131                 [[adium preferenceController] setPreference:[NSNumber numberWithInt:keySelection]
132                                                                                          forKey:KEY_TAB_SWITCH_KEYS
133                                                                                           group:PREF_GROUP_CHAT_CYCLING];
134                 
135         } else if (sender == popUp_sendKeys) {
136                 AISendKeys      keySelection = [[sender selectedItem] tag];
137                 BOOL            sendOnEnter = (keySelection == AISendOnEnter || keySelection == AISendOnBoth);
138                 BOOL            sendOnReturn = (keySelection == AISendOnReturn || keySelection == AISendOnBoth);
139                 
140                 [[adium preferenceController] setPreference:[NSNumber numberWithInt:sendOnEnter]
141                                                                                          forKey:SEND_ON_ENTER
142                                                                                           group:PREF_GROUP_GENERAL];
143                 [[adium preferenceController] setPreference:[NSNumber numberWithInt:sendOnReturn]
144                                                                                          forKey:SEND_ON_RETURN
145                                               group:PREF_GROUP_GENERAL];
146         } else if (sender == checkBox_updatesAutomatic) {
147                 [[NSUserDefaults standardUserDefaults] setBool:[sender state] forKey:@"SUCheckAtStartup"];
148                 [self configureControlDimming];
149         } else if (sender == checkBox_updatesProfileInfo) {
150                 [[NSUserDefaults standardUserDefaults] setBool:[sender state] forKey:@"SUIncludeProfile"];
151         } else if (sender == checkBox_updatesIncludeBetas) {
152                 [[NSUserDefaults standardUserDefaults] setBool:[sender state] forKey:@"AIAlwaysUpdateToBetas"];
153         }
156 //Dim controls as needed
157 - (void)configureControlDimming
159         [checkBox_arrangeByGroup setEnabled:[checkBox_messagesInTabs state]];
160         [checkBox_updatesProfileInfo setEnabled:[checkBox_updatesAutomatic state]];
161         [checkBox_updatesIncludeBetas setEnabled:[checkBox_updatesAutomatic state]];
165  * @brief Construct our menu by hand for easy localization
166  */
167 - (NSMenu *)tabChangeKeysMenu
169         NSMenu          *menu = [[NSMenu allocWithZone:[NSMenu menuZone]] init];
170 #define PLACE_OF_INTEREST_SIGN  "\u2318"
171 #define LEFTWARDS_ARROW                 "\u2190"
172 #define RIGHTWARDS_ARROW                "\u2192"
173 #define SHIFT_ARROW                             "\u21E7"
175         [menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Arrows (%@ and %@)","Directional arrow keys word"), [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN LEFTWARDS_ARROW], [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN RIGHTWARDS_ARROW]]
176                                         target:nil
177                                         action:nil
178                          keyEquivalent:@""
179                                            tag:AISwitchArrows];
180         
181         [menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Shift + Arrows (%@ and %@)","Shift key word + Directional arrow keys word"), [NSString stringWithUTF8String:SHIFT_ARROW PLACE_OF_INTEREST_SIGN LEFTWARDS_ARROW], [NSString stringWithUTF8String:SHIFT_ARROW PLACE_OF_INTEREST_SIGN RIGHTWARDS_ARROW]]
182                                         target:nil
183                                         action:nil
184                          keyEquivalent:@""
185                                            tag:AISwitchShiftArrows];
186         
187         [menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Brackets (%@ and %@)","Word for [ and ] keys"), [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "["], [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "]"]]
188                                         target:nil
189                                         action:nil
190                          keyEquivalent:@""
191                                            tag:AIBrackets];
192         
193         [menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Curly braces (%@ and %@)","Word for { and } keys"), [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "{"], [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "}"]]
194                                         target:nil
195                                         action:nil
196                          keyEquivalent:@""
197                                            tag:AIBraces];
198         
199         return [menu autorelease];              
202 - (BOOL)shortcutRecorder:(SRRecorderControl *)aRecorder isKeyCode:(signed short)keyCode andFlagsTaken:(unsigned int)flags reason:(NSString **)aReason
204         return NO;
207 - (void)shortcutRecorder:(SRRecorderControl *)aRecorder keyComboDidChange:(KeyCombo)newKeyCombo
209         if (aRecorder == shortcutRecorder) {
210                 PTKeyCombo *keyCombo = [PTKeyCombo keyComboWithKeyCode:[shortcutRecorder keyCombo].code
211                                                                                                          modifiers:[shortcutRecorder cocoaToCarbonFlags:[shortcutRecorder keyCombo].flags]];
212                 [[adium preferenceController] setPreference:[keyCombo plistRepresentation]
213                                                                                          forKey:KEY_GENERAL_HOTKEY
214                                                                                           group:PREF_GROUP_GENERAL];
215         }
219  * @brief Construct our menu by hand for easy localization
220  */
221 - (NSMenu *)sendKeysMenu
223         NSMenu          *menu = [[NSMenu allocWithZone:[NSMenu menuZone]] init];
225         [menu addItemWithTitle:AILocalizedString(@"Enter","Enter key for sending messages")
226                                         target:nil
227                                         action:nil
228                          keyEquivalent:@""
229                                            tag:AISendOnEnter];
231         [menu addItemWithTitle:AILocalizedString(@"Return","Return key for sending messages")
232                                         target:nil
233                                         action:nil
234                          keyEquivalent:@""
235                                            tag:AISendOnReturn];
237         [menu addItemWithTitle:AILocalizedString(@"Enter and Return","Enter and return key for sending messages")
238                                         target:nil
239                                         action:nil
240                          keyEquivalent:@""
241                                            tag:AISendOnBoth];
243         return [menu autorelease];              
246 - (NSMenu *)tabPositionMenu
248         NSMenu          *menu = [[NSMenu allocWithZone:[NSMenu menuZone]] init];
249         
250         [menu addItemWithTitle:AILocalizedString(@"Top","Position menu item for tabs at the top of the message window")
251                                         target:nil
252                                         action:nil
253                          keyEquivalent:@""
254                                            tag:AdiumTabPositionTop];
255         
256         [menu addItemWithTitle:AILocalizedString(@"Bottom","Position menu item for tabs at the bottom of the message window")
257                                         target:nil
258                                         action:nil
259                          keyEquivalent:@""
260                                            tag:AdiumTabPositionBottom];
261         
262         [menu addItemWithTitle:AILocalizedString(@"Left","Position menu item for tabs at the left of the message window")
263                                         target:nil
264                                         action:nil
265                          keyEquivalent:@""
266                                            tag:AdiumTabPositionLeft];
268         [menu addItemWithTitle:AILocalizedString(@"Right","Position menu item for tabs at the right of the message window")
269                                         target:nil
270                                         action:nil
271                          keyEquivalent:@""
272                                            tag:AdiumTabPositionRight];
273         
274         return [menu autorelease];              
277 #pragma mark Message history
278 - (IBAction)configureMessageHistory:(id)sender
280         [AIMessageHistoryPreferencesWindowController configureMessageHistoryPreferencesOnWindow:[[self view] window]];
283 @end